package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.bean.PageRes;

import java.util.List;

/**
 * BaseMapper MybatisPlus基础接口，提供基础CRUD
 * MPJBaseMapper MybatisPlusJoin基础接口，提供连表join
 * @param <T>
 */
public interface BaseMapperX<T> extends BaseMapper<T> {

    default PageRes<T> selectPageCommon(Page<T> page, Wrapper<T> queryWrapper) {
        Page<T> tPage = this.selectPage(page, queryWrapper);
        return new PageRes<>(tPage.getRecords(),tPage.getTotal());
    }

    default PageRes<T> selectPageCommon(Wrapper<T> queryWrapper) {
        List<T> records = this.selectList(queryWrapper);
        Long total = this.selectCount(queryWrapper);
        return new PageRes<>(records,total);
    }
}
